import { relationalStore } from "@kit.ArkData"
import { Field, FieldType } from "../Field"
import { Table } from "../Table"

/**
 * 填空题：Fill-in-the-blank question

 判断题：True/False question

 匹配题：Matching question

 简答题：Short-answer question

 计算题：Calculation question

 Essay question / Open-ended question // 问答题
 */


export enum BdQuestionType {
  SingleChoice, //单选题
  MultiChoice, //多选题
  Essay, //问答题
}

export class BdQuestionEntity {
  id: number = 0
  title: string = ""
  answer: string = ""
  //字符串数组, 搜索时不能用逗号,
  tags: string = ""
  folderId: number = 0;

  type: BdQuestionType = BdQuestionType.Essay

  static fieldsName: string [] = [];

  static initClass() {
    //如果属性没有默认值,其key获取不到.
    const obj = new BdQuestionEntity();
    this.fieldsName = Object.getOwnPropertyNames(obj);
  }

  //
  getValueBucket(): relationalStore.ValuesBucket {
    const bucket = {};
    BdQuestionEntity.fieldsName.forEach(prop => {
      if (this[prop] === undefined) {
        return
      }
      bucket[prop] = this[prop];
    });
    return bucket;
  }

  /**
   * 手动返回函数指定
   * @returns
   */
  static getTable_custom(): Table {
    const tbName = "question";
    const table = new Table(tbName);
    const fields: Field[] = [];
    {
      const f = new Field("id", FieldType.Int);
      f.primaryKey = true;
      f.autoIncrement = true;
      fields.push(f);
    }
    {
      const f = new Field("title", FieldType.String);
      fields.push(f);
    }
    {
      const f = new Field("answer", FieldType.String);
      fields.push(f);
    }
    {
      const f = new Field("tags", FieldType.String);
      fields.push(f);
    }
    {
      const f = new Field("folderId", FieldType.Int);
      fields.push(f);
    }
    {
      const f = new Field("type", FieldType.Int);
      fields.push(f);
    }
    table.fields = fields;
    return table;
  }
}

// type _BdQuestionCreateDto =

// export type BdQuestionCreateDto = Partial<Omit<BdQuestionEntity, "id">>

// 定义 CreateDto 类型
export type CreateDto<T> = Partial<Omit<Pick<T, {
  [K in keyof T]: T[K] extends Function ? never : K
}[keyof T]>,
'id'>>;

export function getCreateDto<T>(): CreateDto<T> {
  return {};
}